@extends('web.layout')

@section('styles')
    <style>
        .layui-form-pane .layui-form-label {
            width: 150px;
        }
    </style>
@endsection

@section('content')
    <div class="layui-container fly-marginTop fly-user-main">
        @include('web.user.nav')

        <div class="fly-panel fly-panel-user" pad20>
            <div class="layui-tab layui-tab-brief" lay-filter="user">
                <ul class="layui-tab-title" id="LAY_mine">
                    <li class="layui-this" lay-id="info">我的资料</li>
                    <li lay-id="avatar">头像</li>
                    <li lay-id="pass">密码</li>
                </ul>
                <div class="layui-tab-content" style="padding: 20px 0;">
                    <div class="layui-form layui-form-pane layui-tab-item layui-show">
                        <form method="post" action="{{ url('/user-update') }}">
                            @if($user && isset($user->autoOrder) && $user->autoOrder->sorting > 0)
                            <div class="layui-form-item">
                                <label for="L_union_name" class="layui-form-label">自动接单</label>
                                <div class="layui-input-block">
                                    <input type="radio" name="auto_status" value="1" lay-filter="admin" title="开启"
                                           @if($user && $user->autoOrder->status == 1)
                                           checked
                                            @endif
                                    >
                                    <input type="radio" name="auto_status" value="0" lay-filter="admin" title="关闭"
                                           @if($user && $user->autoOrder->status == 0)
                                           checked
                                            @endif
                                    >
                                </div>
                            </div>
                            @endif
                            <div class="layui-form-item">
                                <label for="L_name" class="layui-form-label">昵称</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_name" name="name" required lay-verify="required" autocomplete="off" value="{{ $user->name }}" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_alipay_account" class="layui-form-label">提现支付宝账户</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_alipay_account" name="alipay_account" autocomplete="off" value="{{ $user->alipay_account }}" class="layui-input layui-disabled" disabled>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_alipay_name" disabled class="layui-form-label">提现支付宝姓名</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_alipay_name" name="alipay_name" autocomplete="off" value="{{ $user->alipay_name }}" class="layui-input layui-disabled" disabled>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_receive_order_price" class="layui-form-label">接单金额</label>
                                <div class="layui-input-inline">
                                    <input type="number" id="L_receive_order_price" name="receive_order_price" required lay-verify="required" autocomplete="off" value="{{ $user->receive_order_price }}" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_union_name" class="layui-form-label">联盟名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_union_name" name="union_name" autocomplete="off" value="{{ $user->union_name }}" class="layui-input layui-disabled" disabled>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_union_name" class="layui-form-label">联盟群号</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_union_qq" name="union_qq" autocomplete="off" value="{{ $user->union_qq }}" class="layui-input layui-disabled" disabled>
                                </div>
                            </div>

                            <div class="layui-form-item layui-form-text">
                                <label for="L_union_desc" class="layui-form-label">联盟介绍</label>
                                <div class="layui-input-block">
                                    <textarea placeholder="联盟介绍" id="L_union_desc"  name="union_desc" autocomplete="off" class="layui-textarea" style="height: 80px;">{{ $user->union_desc }}</textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <button class="layui-btn" lay-filter="*" lay-submit>确认修改</button>
                            </div>
                        </form>
                    </div>

                    <div class="layui-form layui-form-pane layui-tab-item">
                        <div class="layui-form-item">
                            <div class="avatar-add">
                                <p>建议尺寸168*168，支持jpg、png、gif，最大不能超过50KB</p>
                                <button type="button" class="layui-btn upload-img" id="uploadImg">
                                    <i class="layui-icon">&#xe67c;</i>上传头像
                                </button>
                                <img src="{{ $user->avatar ? $user->avatar : asset('web/images/default.png') }}" id="previewImg">
                                <span class="loading"></span>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form layui-form-pane layui-tab-item">
                        <form action="{{ url('/user-repass') }}" method="post">
                            <div class="layui-form-item">
                                <label for="L_nowpass" class="layui-form-label">当前密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_nowpass" name="old_password" required lay-verify="required" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_pass" class="layui-form-label">新密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_pass" name="password" required lay-verify="required" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid layui-word-aux">6到16个字符</div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_repass" class="layui-form-label">确认密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_repass" name="password_confirmation" required lay-verify="required" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <button class="layui-btn" key="set-mine" lay-filter="*" lay-submit>确认修改</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('scripts')
<script>
    layui.use(['form','table','upload','laytpl'], function(){
        var $ = layui.$
            ,layer = layui.layer
            ,upload = layui.upload

        var uploadInst = upload.render({
            elem: '#uploadImg'
            ,url: "{{ url('/update-avatar') }}"
            ,before: function(obj){
                obj.preview(function(index, file, result){
                    $('#previewImg').attr('src', result);
                });
            }
            ,done: function(res){
                if (res.code == 0) {
                    layer.msg(res.msg,{icon:1,time:1000});
                    console.log(res.data.imageUrl);
                    $('#previewImg').attr('src', res.data.imageUrl);
                    $('#user-avatar').attr('src', res.data.imageUrl);
                }else{
                    return layer.msg('上传失败');
                }
            }
            ,error: function(){
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
    });
</script>
@endsection